﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using XChipTool.Enties;

namespace XChipTool
{
    public partial class XChip_DeriveAdd : DevExpress.XtraEditors.XtraForm
    {
        public int IDtemp;
        public parameter_exportManager Pe_dal { get; set; }
        public delegate void SendEventDeriveAddClick();
        public event SendEventDeriveAddClick SendDeriveAdd;

        public XChip_DeriveAdd()
        {
            InitializeComponent();
        }
        public XChip_DeriveAdd(int id)
        {
            IDtemp = id;
            InitializeComponent();
        }

        private void XChip_DeriveAdd_Load(object sender, EventArgs e)
        {
            if (Pe_dal == null)
            {
                Pe_dal = new parameter_exportManager();
            }
            var model = Pe_dal.GetSingle(c => c.id == IDtemp);
            moduleText.Text = model.Module;
            addrTxt.Text = model.addr;
            ReadAddrTxt.Text = model.ReadAddr;
            RearNoteTxt.Text = model.RearNote;
            PreNoteTxt.Text = model.PreNote;
            SortNumTxt.Text = model.SortNum.ToString();
        }
        /// <summary>
        /// 新增一条数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            parameter_export model = new parameter_export();
            model.addr = addrTxt.Text;
            model.ReadAddr = ReadAddrTxt.Text;
            model.RearNote = RearNoteTxt.Text;
            model.PreNote = PreNoteTxt.Text;
            model.Module = moduleText.Text;
            model.SortNum = int.Parse(SortNumTxt.Text);
            Pe_dal.Insert(model);
            if (null!=SendDeriveAdd)
            {
                SendDeriveAdd();
            }
        }
    }
}